<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title data-i18n="resources.text_graduatedSymbol"></title>
    <style type="text/css">
        .editPane {
            position: absolute;
            right: 40px;
            top: 50px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
        }
        .btn {
            margin: 0 10px 0px;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_graduatedSymbol"></h5>
    </div>
    <div class='panel-body' id='params'>
        <p></p>
        <div align='right' class='button-group'>
            <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_addThemeLayer" onclick="addThemeGraduatedSymbol()"/>
            <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear" onclick="removeTheme()"/>
        </div>
    </div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text/javascript">
    var map, baseLayer, themeLayer,
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
        url = host + "/iserver/services/map-china400/rest/maps/China";

    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                    enableKinetic: true
                }
            })]
    });
    baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("China400", url, {
        transparent: true,
        cacheEnabled: true
    }, {maxResolution: "auto"});
    baseLayer.events.on({"layerInitialized": addLayer});

    function addLayer() {
        map.addLayer(baseLayer);
        map.setCenter(new SuperMap.LonLat(10080677, 4591416), 4);
        map.allOverlays = true;
    }
    function addThemeGraduatedSymbol() {
        removeTheme();
        var themeService = new SuperMap.REST.ThemeService(url,
            {eventListeners: {"processCompleted": themeCompleted, "processFailed": themeFailed}}),
            graStyle = new SuperMap.REST.ThemeGraduatedSymbolStyle({
                positiveStyle: new SuperMap.REST.ServerStyle({
                    markerSize: 50,
                    markerSymbolID: 0,
                    lineColor: new SuperMap.REST.ServerColor(255, 165, 0),
                    fillBackColor: new SuperMap.REST.ServerColor(255, 0, 0)
                })
            }),
            themeGraduatedSymbol = new SuperMap.REST.ThemeGraduatedSymbol({
                expression: "SMAREA",
                baseValue: 3000000000000,
                graduatedMode: SuperMap.REST.GraduatedMode.CONSTANT,
                flow: new SuperMap.REST.ThemeFlow({
                    flowEnabled: true
                }),
                style: graStyle
            }),
            themeParameters = new SuperMap.REST.ThemeParameters({
                themes: [themeGraduatedSymbol],
                datasetNames: ["China_Province_pg"],
                dataSourceNames: ["China"],
                types: ['REGION']
            });

        themeService.processAsync(themeParameters);
    }

    function themeCompleted(themeEventArgs) {
        if (themeEventArgs.result.resourceInfo.id) {
            themeLayer = new SuperMap.Layer.TiledDynamicRESTLayer("中国各省面积等级符号专题图",
                url,
                {
                    cacheEnabled: false, transparent: true,
                    layersID: themeEventArgs.result.resourceInfo.id
                },
                {"maxResolution": "auto"});
            themeLayer.events.on({"layerInitialized": addThemelayer});
        }
    }
    function addThemelayer() {
        map.addLayer(themeLayer);
    }

    function themeFailed(serviceFailedEventArgs) {
        //doMapAlert("",serviceFailedEventArgs.error.errorMsg,true);
        widgets.alert.showAlert(serviceFailedEventArgs.error.errorMsg,false);
    }

    function removeTheme() {
        if (map.layers.length > 1) {
            map.removeLayer(themeLayer, true);
        }
    }
</script>
</body>
</html>
